package com.src.myapplication.utils;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.src.myapplication.ui.view.fragmentpemgyou.FrgmentFuJing;
import com.src.myapplication.ui.view.fragmentpemgyou.FrgmentHaoYou;
import com.src.myapplication.ui.view.fragmentpemgyou.FrgmentPaiHang;
import com.src.myapplication.ui.view.fragmentpemgyou.FrgmentPengYouQuan;

/**
 * 类描述:
 * 创建人:
 * 创建时间:2016/10/11
 * 备注:fragment工厂
 */
public class FragmentFactory_PengYou {

    private static final int FRAGMENT_Min0 = 0;
    private static final int FRAGMENT_Min1 = 1;
    private static final int FRAGMENT_Min2 = 2;
    private static final int FRAGMENT_Min3 = 3;

    //SparseArray:key是整形的key,根据整形的key来获取一个对象,效率比较高.
    public static SparseArray<Fragment> fragments_pengyou = new SparseArray<>();

    public static Fragment createFragment_pengyou(int index) {
        //从集合中获取
        Fragment fragment = fragments_pengyou.get(index);
        if (fragment == null) {
            switch (index) {
                case FRAGMENT_Min0:
                    fragment = new FrgmentPengYouQuan();
                    break;
                case FRAGMENT_Min1:
                    fragment = new FrgmentHaoYou();
                    break;
                case FRAGMENT_Min2:
                    fragment = new FrgmentPaiHang();
                    break;
                case FRAGMENT_Min3:
                    fragment = new FrgmentFuJing();
                    break;
            }
            //存到集合中
            fragments_pengyou.put(index, fragment);
        }

        return fragment;
    }

}
